go to previous page   go to home page   go to next page hear noise

Answer:

Maybe. However, even with type double, overflow is reached at N==170.


Live Factorial Calculator

Another problem with double is that the result is only an approximation to the exact value. doubles have the equivalent of about 15 decimal digits of accuracy. This might not be good enough. For example, if you are doing number theory, approximations are useless.

Often math formulas use factorial, but explicit calculation of factorial can be avoided by rearranging the operations of the formula. Avoid explicit calculation of factorial. For example, the number of arrangements that can be made of r objects selected from n objects is: n! / (n-r)!

Say that you want to select 5 objects out of 30. It looks like you need to calculate both 30! and 25! both of which would be disasters. But using cancellation, the formula becomes:

30 * 29 * 28 * 27 * 26

which can be calculated without problems.

Here is a Javascript version of the factorial calculator:


Enter N:

Try some values for N that test the boundaries: -1, 0, 20. Then try some small values like 6 or 12.


QUESTION 13:

If you drop a brick from a tower, what happens?